package com.example.jiangkt.ergongyi.activity;

import android.app.Activity;
import android.app.AlertDialog;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Matrix;
import android.graphics.Paint;
import android.os.Bundle;
import android.os.CountDownTimer;
import android.text.Spannable;
import android.text.SpannableStringBuilder;
import android.text.style.ForegroundColorSpan;
import android.view.Gravity;
import android.view.KeyEvent;
import android.view.View;
import android.widget.Button;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.NumberPicker;
import android.widget.TextView;
import android.widget.Toast;

import com.alibaba.fastjson.JSONObject;
import com.example.jiangkt.ergongyi.R;
import com.example.jiangkt.ergongyi.adapter.PlayerListAdapter;
import com.example.jiangkt.ergongyi.entity.Seat;
import com.example.jiangkt.ergongyi.util.CardUtil;
import com.example.jiangkt.ergongyi.util.CustomAction;
import com.example.jiangkt.ergongyi.view.CustomNumberPicker;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class UserRoomActivity extends Activity implements View.OnClickListener {
    private TextView tv_first;
    private TextView tv_second;
    private TextView tv_third;
    private TextView tv_fourth;
    private TextView tv_fifth;

    private ImageView iv_pointer_first;
    private ImageView iv_pointer_second;
    private ImageView iv_pointer_third;
    private ImageView iv_pointer_fourth;
    private ImageView iv_pointer_fifth;

    private ImageView iv_get_card;
    private ImageView iv_next_player;
    private TextView tv_get_card;
    private TextView tv_next_player;

    private String selfSeat;
    private JSONObject selfSeatJson;
    private String selfUserName;
    private String selfSeatNo;
    private long selfSeatNoNum;

    private ImageView imageView1;
    private ImageView imageView2;

    private ImageView first_one;
    private ImageView first_two;
    private ImageView first_three;
    private ImageView first_four;
    private ImageView first_five;

    private ImageView second_one;
    private ImageView second_two;
    private ImageView second_three;
    private ImageView second_four;
    private ImageView second_five;

    private ImageView third_one;
    private ImageView third_two;
    private ImageView third_three;
    private ImageView third_four;
    private ImageView third_five;

    private ImageView fourth_one;
    private ImageView fourth_two;
    private ImageView fourth_three;
    private ImageView fourth_four;
    private ImageView fourth_five;

    private ImageView fifth_one;
    private ImageView fifth_two;
    private ImageView fifth_three;
    private ImageView fifth_four;
    private ImageView fifth_five;

    private ImageView first_banker;
    private ImageView second_banker;
    private ImageView third_banker;
    private ImageView fourth_banker;
    private ImageView fifth_banker;

    private ImageView iv_deal;
    private UserRoomReceiver userRoomReceiver;
    //第一个座位
    private FrameLayout.LayoutParams firstOneLayoutParams = null;
    private FrameLayout.LayoutParams firstTwoLayoutParams = null;
    private FrameLayout.LayoutParams firstThreeLayoutParams = null;
    private FrameLayout.LayoutParams firstFourLayoutParams = null;
    private FrameLayout.LayoutParams firstFiveLayoutParams = null;
    //第二个座位
    private FrameLayout.LayoutParams secondOneLayoutParams = null;
    private FrameLayout.LayoutParams secondTwoLayoutParams = null;
    private FrameLayout.LayoutParams secondThreeLayoutParams = null;
    private FrameLayout.LayoutParams secondFourLayoutParams = null;
    private FrameLayout.LayoutParams secondFiveLayoutParams = null;
    //第三个座位
    private FrameLayout.LayoutParams thirdOneLayoutParams = null;
    private FrameLayout.LayoutParams thirdTwoLayoutParams = null;
    private FrameLayout.LayoutParams thirdThreeLayoutParams = null;
    private FrameLayout.LayoutParams thirdFourLayoutParams = null;
    private FrameLayout.LayoutParams thirdFiveLayoutParams = null;
    //第四个座位
    private FrameLayout.LayoutParams fourthOneLayoutParams = null;
    private FrameLayout.LayoutParams fourthTwoLayoutParams = null;
    private FrameLayout.LayoutParams fourthThreeLayoutParams = null;
    private FrameLayout.LayoutParams fourthFourLayoutParams = null;
    private FrameLayout.LayoutParams fourthFiveLayoutParams = null;
    //第五个座位
    private FrameLayout.LayoutParams fifthOneLayoutParams = null;
    private FrameLayout.LayoutParams fifthTwoLayoutParams = null;
    private FrameLayout.LayoutParams fifthThreeLayoutParams = null;
    private FrameLayout.LayoutParams fifthFourLayoutParams = null;
    private FrameLayout.LayoutParams fifthFiveLayoutParams = null;

    private CustomNumberPicker np_select_escrow;

    private ImageView iv_first_escrow;
    private ImageView iv_second_escrow;
    private ImageView iv_third_escrow;
    private ImageView iv_fourth_escrow;
    private ImageView iv_fifth_escrow;

    private TextView tv_first_escrow;
    private TextView tv_second_escrow;
    private TextView tv_third_escrow;
    private TextView tv_fourth_escrow;
    private TextView tv_fifth_escrow;

    private TextView tv_self_chip;
    private int selfChip = 0;//等于所押筹码加上保留的筹码
    private int defaultEscrowValue = 0;

    private String joinUserName;
    private String joinSeatNo;
    private String selfSeatId;
    private String seats;
    private ImageView second_eye;
    private ImageView third_eye;
    private ImageView fourth_eye;
    private ImageView fifth_eye;
    private boolean secondEye;
    private boolean thirdEye;
    private boolean fourthEye;
    private boolean fifthEye;
    private String userLimit;
    private String upperChip;
    private String lowerChip;
    private String pointerSeatNo;

    private boolean settlementStatus = false;

    private TextView tv_show_time;

    private String selfRoomId;
    private List<Integer> selfCards = new ArrayList<>();
    private TextView tv_select_escrow;
    private LinearLayout ll_select_escrow;
    private AlertDialog settlementDialog;
    private AlertDialog bankerDialog;
    private TextView banker_chip;
    private TextView self_chip;
    private LinearLayout player_settlement;
    private Button return_main;
    private String userId;
    private LinearLayout banker_settlement;
    private Button return_main_banker;
    private List<Map<String, String>> playerList = new ArrayList<>();
    private Map<String, String> secondMap = new HashMap<>();
    private Map<String, String> thirdMap = new HashMap<>();
    private Map<String, String> fourthMap = new HashMap<>();
    private Map<String, String> fifthMap = new HashMap<>();
    private ListView player_list;
    private TextView banker_chip_banker;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_user_room);

        initViewId();
        initReceiver();
        initIntent();

//        initSelectEscrow();

        initSendBroadcast();

        initViews();


        initCards();
    }

    @Override
    protected void onPause() {
        super.onPause();
        if (bankerDialog!=null){
            bankerDialog.dismiss();
        }
        if (settlementDialog!=null){
            settlementDialog.dismiss();
        }
    }

    /**
     * 动态初始化选择筹码数值选择器
     */
    private void initSelectEscrow() {
        iv_first_escrow.setImageResource(R.drawable.bet_room_asset_description_pop_right_coins);
        tv_select_escrow = new TextView(this);
        tv_select_escrow.setGravity(Gravity.CENTER);
        tv_select_escrow.setTextColor(getApplication().getResources().getColor(R.color.colorWhite));
        tv_select_escrow.setText("请在6秒内选择筹码");
        np_select_escrow = new CustomNumberPicker(this);
        ll_select_escrow.addView(np_select_escrow);
        ll_select_escrow.addView(tv_select_escrow);

//        this.dealPointer();

        defaultEscrowValue = defaultEscrowValue == 0 ? Integer.parseInt(lowerChip) : defaultEscrowValue;
        np_select_escrow.setMaxValue(Integer.parseInt(upperChip));
        np_select_escrow.setMinValue(Integer.parseInt(lowerChip));
        np_select_escrow.setValue(defaultEscrowValue);
//        selfChip -= defaultEscrowValue==0?Integer.parseInt(lowerChip):defaultEscrowValue;
        tv_first_escrow.setText(defaultEscrowValue + "");
        tv_self_chip.setText((selfChip - defaultEscrowValue) + "");
        np_select_escrow.setOnValueChangedListener(new NumberPicker.OnValueChangeListener() {
            @Override
            public void onValueChange(NumberPicker picker, int oldVal, int newVal) {
//                selfChip = selfChip + oldVal - newVal;
                defaultEscrowValue = newVal;
                tv_first_escrow.setText(defaultEscrowValue + "");
                tv_self_chip.setText((selfChip - defaultEscrowValue) + "");
            }
        });

        new CountDownTimer(6 * 1000, 1000) {
            @Override
            public void onTick(long millisUntilFinished) {
                tv_select_escrow.setText("请在" + millisUntilFinished / 1000 + "秒内选择筹码");

                SpannableStringBuilder builder = new SpannableStringBuilder(tv_select_escrow.getText().toString());
                ForegroundColorSpan redSpan = new ForegroundColorSpan(Color.RED);
                builder.setSpan(redSpan, 2, 3, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
                tv_select_escrow.setText(builder);
            }

            @Override
            public void onFinish() {
                Intent sendEscrowIntent = new Intent(CustomAction.SERVICE_ACTION);
                Map<String, Object> sendEscrowMap = new HashMap<>();
                sendEscrowMap.put("reqType", "sendEscrowReq");
                sendEscrowMap.put("seatId", selfSeatId);
                sendEscrowMap.put("escrow", tv_first_escrow.getText().toString());
                sendEscrowIntent.putExtra("request", JSONObject.toJSON(sendEscrowMap).toString());
                sendBroadcast(sendEscrowIntent);
                ll_select_escrow.removeView(np_select_escrow);
                ll_select_escrow.removeView(tv_select_escrow);
            }
        }.start();
    }

    /**
     * 没用到
     */
    private void dealPointer() {
        if ("2".equals(userLimit)) {
            iv_pointer_second.setImageResource(R.drawable.pointer);
        } else if ("3".equals(userLimit)) {
            iv_pointer_second.setImageResource(R.drawable.pointer);
            iv_pointer_third.setImageResource(R.drawable.pointer);
        } else if ("4".equals(userLimit)) {
            iv_pointer_second.setImageResource(R.drawable.pointer);
            iv_pointer_third.setImageResource(R.drawable.pointer);
            iv_pointer_fourth.setImageResource(R.drawable.pointer);
        } else if ("5".equals(userLimit)) {
            iv_pointer_second.setImageResource(R.drawable.pointer);
            iv_pointer_third.setImageResource(R.drawable.pointer);
            iv_pointer_fourth.setImageResource(R.drawable.pointer);
            iv_pointer_fifth.setImageResource(R.drawable.pointer);
        }
    }

    private void initBankerChip() {
        tv_self_chip.setText(selfChip + "");

//        this.dealPointer();
        new CountDownTimer(8 * 1000, 1000) {
            @Override
            public void onTick(long millisUntilFinished) {
            }

            @Override
            public void onFinish() {
                Intent sendEscrowIntent = new Intent(CustomAction.SERVICE_ACTION);
                Map<String, Object> sendEscrowMap = new HashMap<>();
                sendEscrowMap.put("reqType", "getDealCardReq");
                sendEscrowMap.put("seatId", selfSeatId);
                sendEscrowIntent.putExtra("request", JSONObject.toJSON(sendEscrowMap).toString());
                sendBroadcast(sendEscrowIntent);
            }
        }.start();
    }

    /**
     * 得到相对位置
     *
     * @param otherSeatNoNum
     * @return
     */
    private int getRelativeSeatNo(int otherSeatNoNum) {
        return otherSeatNoNum > Integer.parseInt(selfSeatNo) ? otherSeatNoNum - Integer.parseInt(selfSeatNo) : otherSeatNoNum + 5 - Integer.parseInt(selfSeatNo);
    }

    private void initViewId() {
        tv_first = findViewById(R.id.ur_tv_first);
        tv_second = findViewById(R.id.ur_tv_second);
        tv_third = findViewById(R.id.ur_tv_third);
        tv_fourth = findViewById(R.id.ur_tv_fourth);
        tv_fifth = findViewById(R.id.ur_tv_fifth);

        iv_pointer_first = findViewById(R.id.iv_pointer_first);
        iv_pointer_second = findViewById(R.id.iv_pointer_second);
        iv_pointer_third = findViewById(R.id.iv_pointer_third);
        iv_pointer_fourth = findViewById(R.id.iv_pointer_fourth);
        iv_pointer_fifth = findViewById(R.id.iv_pointer_fifth);

        first_one = findViewById(R.id.first_card_one);
        first_two = findViewById(R.id.first_card_two);
        first_three = findViewById(R.id.first_card_three);
        first_four = findViewById(R.id.first_card_four);
        first_five = findViewById(R.id.first_card_five);

        second_one = findViewById(R.id.second_card_one);
        second_two = findViewById(R.id.second_card_two);
        second_three = findViewById(R.id.second_card_three);
        second_four = findViewById(R.id.second_card_four);
        second_five = findViewById(R.id.second_card_five);

        third_one = findViewById(R.id.third_card_one);
        third_two = findViewById(R.id.third_card_two);
        third_three = findViewById(R.id.third_card_three);
        third_four = findViewById(R.id.third_card_four);
        third_five = findViewById(R.id.third_card_five);

        fourth_one = findViewById(R.id.fourth_card_one);
        fourth_two = findViewById(R.id.fourth_card_two);
        fourth_three = findViewById(R.id.fourth_card_three);
        fourth_four = findViewById(R.id.fourth_card_four);
        fourth_five = findViewById(R.id.fourth_card_five);

        fifth_one = findViewById(R.id.fifth_card_one);
        fifth_two = findViewById(R.id.fifth_card_two);
        fifth_three = findViewById(R.id.fifth_card_three);
        fifth_four = findViewById(R.id.fifth_card_four);
        fifth_five = findViewById(R.id.fifth_card_five);

        first_banker = findViewById(R.id.first_banker_logo);
        second_banker = findViewById(R.id.second_banker_logo);
        third_banker = findViewById(R.id.third_banker_logo);
        fourth_banker = findViewById(R.id.fourth_banker_logo);
        fifth_banker = findViewById(R.id.fifth_banker_logo);

        iv_deal = findViewById(R.id.iv_deal);
        iv_deal.setOnClickListener(UserRoomActivity.this);
        iv_deal.setClickable(false);

        iv_get_card = findViewById(R.id.iv_get_card);
        tv_get_card = findViewById(R.id.tv_get_card);
        iv_get_card.setOnClickListener(UserRoomActivity.this);
        iv_get_card.setClickable(false);
        iv_next_player = findViewById(R.id.iv_next_player);
        tv_next_player = findViewById(R.id.tv_next_player);
        iv_next_player.setOnClickListener(UserRoomActivity.this);
        iv_next_player.setClickable(false);

        second_eye = findViewById(R.id.second_eye);
        third_eye = findViewById(R.id.third_eye);
        fourth_eye = findViewById(R.id.fourth_eye);
        fifth_eye = findViewById(R.id.fifth_eye);
        second_eye.setOnClickListener(this);
        second_eye.setClickable(false);
        third_eye.setOnClickListener(this);
        third_eye.setClickable(false);
        fourth_eye.setOnClickListener(this);
        fourth_eye.setClickable(false);
        fifth_eye.setOnClickListener(this);
        fifth_eye.setClickable(false);

        iv_first_escrow = findViewById(R.id.iv_first_escrow);
        iv_second_escrow = findViewById(R.id.iv_second_escrow);
        iv_third_escrow = findViewById(R.id.iv_third_escrow);
        iv_fourth_escrow = findViewById(R.id.iv_fourth_escrow);
        iv_fifth_escrow = findViewById(R.id.iv_fifth_escrow);

        tv_first_escrow = findViewById(R.id.tv_first_escrow);
        tv_second_escrow = findViewById(R.id.tv_second_escrow);
        tv_third_escrow = findViewById(R.id.tv_third_escrow);
        tv_fourth_escrow = findViewById(R.id.tv_fourth_escrow);
        tv_fifth_escrow = findViewById(R.id.tv_fifth_escrow);

        tv_self_chip = findViewById(R.id.tv_self_chip);
        tv_self_chip.setText(selfChip + "");

        ll_select_escrow = findViewById(R.id.ll_select_escrow);
        tv_show_time = findViewById(R.id.tv_show_time);
    }

    private void initSendBroadcast() {
        Intent seatIntent = new Intent(CustomAction.SERVICE_ACTION);
        Map<String, Object> seatMap = new HashMap<>();
        seatMap.put("reqType", "sendSeatReq");
        seatMap.put("seatId", selfSeatId);
        seatIntent.putExtra("request", JSONObject.toJSON(seatMap).toString());
        sendBroadcast(seatIntent);
    }

    private void initIntent() {
        Intent intent = getIntent();
        selfSeat = intent.getSerializableExtra("selfSeat").toString();
        userId = intent.getSerializableExtra("userId").toString();
        selfSeatJson = JSONObject.parseObject(selfSeat);
        selfRoomId = selfSeatJson.getString("roomId");
        selfSeatId = selfSeatJson.getString("seatId");
        selfSeatNo = selfSeatJson.getString("seatNo");
        selfUserName = selfSeatJson.getString("userName");
        userLimit = selfSeatJson.getString("userLimit");
        upperChip = selfSeatJson.getString("upperChip");
        lowerChip = selfSeatJson.getString("lowerChip");
    }

    private void initReceiver() {
        IntentFilter filter = new IntentFilter(CustomAction.SEAT_ACTION);
        userRoomReceiver = new UserRoomReceiver();
        registerReceiver(userRoomReceiver, filter);
    }

    private void initViews() {
        imageView1 = findViewById(R.id.imageView1);
        imageView2 = findViewById(R.id.imageView2);

        Bitmap bm = BitmapFactory.decodeResource(getResources(), R.drawable.bet_room_table);
        imageView1.setImageBitmap(bm);

        Bitmap modBm = Bitmap.createBitmap(bm.getWidth(), bm.getHeight(), bm.getConfig());
        Canvas canvas = new Canvas(modBm);
        Paint paint = new Paint();
        paint.setColor(Color.BLACK);
        paint.setAntiAlias(true);
        Matrix matrix = new Matrix();
        //matrix.setRotate(90, bm.getWidth()/2, bm.getHeight()/2);
        //matrix.setTranslate(20, 20);
        //镜子效果
        matrix.setScale(-1, 1);
        matrix.postTranslate(bm.getWidth(), 0);

        canvas.drawBitmap(bm, matrix, paint);
        imageView2.setImageBitmap(modBm);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.iv_deal:
                Intent dealIntent = new Intent(CustomAction.SERVICE_ACTION);
                Map<String, Object> dealMap = new HashMap<>();
                dealMap.put("reqType", "dealReq");
                dealMap.put("roomId", selfRoomId);
                dealMap.put("userLimit", userLimit);
                dealIntent.putExtra("request", JSONObject.toJSON(dealMap).toString());
                sendBroadcast(dealIntent);
                //玩家座位号为 0 时，也是就房主时
                iv_deal.setClickable(false);
                iv_deal.setImageResource(CardUtil.cards[55]);
                secondEye = true;
                thirdEye = true;
                fourthEye = true;
                fifthEye = true;
                settlementStatus = false;
                break;
            case R.id.iv_get_card:
                Intent getCardIntent = new Intent(CustomAction.SERVICE_ACTION);
                Map<String, Object> getCardMap = new HashMap<>();
                getCardMap.put("reqType", "getCardReq");
                getCardMap.put("seatId", selfSeatId);
                getCardIntent.putExtra("request", JSONObject.toJSON(getCardMap).toString());
                sendBroadcast(getCardIntent);
                break;
            case R.id.iv_next_player:
                iv_get_card.setImageResource(CardUtil.cards[55]);
                tv_get_card.setText("");
                iv_get_card.setClickable(false);
                iv_next_player.setImageResource(CardUtil.cards[55]);
                iv_next_player.setClickable(false);
                tv_next_player.setText("");
                //如果是房主时，这个图标是开牌
                if ("0".equals(selfSeatNo)) {
                    second_eye.setImageResource(CardUtil.cards[55]);
                    second_eye.setClickable(false);
                    third_eye.setImageResource(CardUtil.cards[55]);
                    third_eye.setClickable(false);
                    fourth_eye.setImageResource(CardUtil.cards[55]);
                    fourth_eye.setClickable(false);
                    fifth_eye.setImageResource(CardUtil.cards[55]);
                    fifth_eye.setClickable(false);
                    settlementStatus = true;
                    iv_deal.setImageResource(R.drawable.select_deal);
                    iv_deal.setClickable(true);

                    Intent openCardIntent = new Intent(CustomAction.SERVICE_ACTION);
                    Map<String, Object> openCardMap = new HashMap<>();
                    openCardMap.put("reqType", "openCardReq");
                    openCardMap.put("seatNo", "");
                    openCardMap.put("roomId", selfRoomId);
                    openCardIntent.putExtra("request", JSONObject.toJSON(openCardMap).toString());
                    sendBroadcast(openCardIntent);
                } else {
                    Intent nextPlayerIntent = new Intent(CustomAction.SERVICE_ACTION);
                    Map<String, Object> map = new HashMap<>();
                    map.put("reqType", "nextPlayerReq");
                    map.put("seatId", selfSeatId);
                    nextPlayerIntent.putExtra("request", JSONObject.toJSON(map).toString());
                    sendBroadcast(nextPlayerIntent);
                }
                break;
            case R.id.second_eye:
                second_eye.setImageResource(CardUtil.cards[55]);
                second_eye.setClickable(false);
                Intent openCardSecondIntent = new Intent(CustomAction.SERVICE_ACTION);
                Map<String, Object> ocsMap = new HashMap<>();
                ocsMap.put("reqType", "openCardReq");
                ocsMap.put("seatNo", "1");
                ocsMap.put("roomId", selfRoomId);
                openCardSecondIntent.putExtra("request", JSONObject.toJSON(ocsMap).toString());
                sendBroadcast(openCardSecondIntent);
                break;
            case R.id.third_eye:
                third_eye.setImageResource(CardUtil.cards[55]);
                third_eye.setClickable(false);
                Intent openCardThirdIntent = new Intent(CustomAction.SERVICE_ACTION);
                Map<String, Object> octMap = new HashMap<>();
                octMap.put("reqType", "openCardReq");
                octMap.put("seatNo", "2");
                octMap.put("roomId", selfRoomId);
                openCardThirdIntent.putExtra("request", JSONObject.toJSON(octMap).toString());
                sendBroadcast(openCardThirdIntent);
                break;
            case R.id.fourth_eye:
                fourth_eye.setImageResource(CardUtil.cards[55]);
                fourth_eye.setClickable(false);
                Intent openCardFourthIntent = new Intent(CustomAction.SERVICE_ACTION);
                Map<String, Object> openCardFourthMap = new HashMap<>();
                openCardFourthMap.put("reqType", "openCardReq");
                openCardFourthMap.put("seatNo", "3");
                openCardFourthMap.put("roomId", selfRoomId);
                openCardFourthIntent.putExtra("request", JSONObject.toJSON(openCardFourthMap).toString());
                sendBroadcast(openCardFourthIntent);
                break;
            case R.id.fifth_eye:
                fifth_eye.setImageResource(CardUtil.cards[55]);
                fifth_eye.setClickable(false);
                Intent openCardFifthIntent = new Intent(CustomAction.SERVICE_ACTION);
                Map<String, Object> openCardFifthMap = new HashMap<>();
                openCardFifthMap.put("reqType", "openCardReq");
                openCardFifthMap.put("seatNo", "4");
                openCardFifthMap.put("roomId", selfRoomId);
                openCardFifthIntent.putExtra("request", JSONObject.toJSON(openCardFifthMap).toString());
                sendBroadcast(openCardFifthIntent);
                break;
            case R.id.return_main:
                Bundle data = new Bundle();
                data.putSerializable("userId", userId);
                data.putSerializable("userName", selfUserName);
                data.putSerializable("roomKey", "0");
                Intent startActivity = new Intent(UserRoomActivity.this, UserInfoActivity.class);
                startActivity.putExtras(data);
                startActivity(startActivity);
                settlementDialog.cancel();
                finish();
                break;
            case R.id.return_main_banker:
                //庄家关闭房间
                Intent closeRoomIntent = new Intent(CustomAction.SERVICE_ACTION);
                Map<String, Object> map = new HashMap<>();
                map.put("reqType", "closeRoomReq");
                map.put("seatId", selfSeatId);
                closeRoomIntent.putExtra("request", JSONObject.toJSON(map).toString());
                sendBroadcast(closeRoomIntent);

                Bundle bankerData = new Bundle();
                bankerData.putSerializable("userId", userId);
                bankerData.putSerializable("userName", selfUserName);
                bankerData.putSerializable("roomKey", "0");
                Intent bankerStartActivity = new Intent(UserRoomActivity.this, UserInfoActivity.class);
                bankerStartActivity.putExtras(bankerData);
                startActivity(bankerStartActivity);
                finish();
                break;

        }
    }

    private void initCards() {
        //第一个座位
        firstOneLayoutParams = (FrameLayout.LayoutParams) first_one.getLayoutParams();
        firstTwoLayoutParams = (FrameLayout.LayoutParams) first_two.getLayoutParams();
        firstThreeLayoutParams = (FrameLayout.LayoutParams) first_three.getLayoutParams();
        firstFourLayoutParams = (FrameLayout.LayoutParams) first_four.getLayoutParams();
        firstFiveLayoutParams = (FrameLayout.LayoutParams) first_five.getLayoutParams();
        //第二个座位
        secondOneLayoutParams = (FrameLayout.LayoutParams) second_one.getLayoutParams();
        secondTwoLayoutParams = (FrameLayout.LayoutParams) second_two.getLayoutParams();
        secondThreeLayoutParams = (FrameLayout.LayoutParams) second_three.getLayoutParams();
        secondFourLayoutParams = (FrameLayout.LayoutParams) second_four.getLayoutParams();
        secondFiveLayoutParams = (FrameLayout.LayoutParams) second_five.getLayoutParams();
        //第三个座位
        thirdOneLayoutParams = (FrameLayout.LayoutParams) third_one.getLayoutParams();
        thirdTwoLayoutParams = (FrameLayout.LayoutParams) third_two.getLayoutParams();
        thirdThreeLayoutParams = (FrameLayout.LayoutParams) third_three.getLayoutParams();
        thirdFourLayoutParams = (FrameLayout.LayoutParams) third_four.getLayoutParams();
        thirdFiveLayoutParams = (FrameLayout.LayoutParams) third_five.getLayoutParams();
        //第四个座位
        fourthOneLayoutParams = (FrameLayout.LayoutParams) fourth_one.getLayoutParams();
        fourthTwoLayoutParams = (FrameLayout.LayoutParams) fourth_two.getLayoutParams();
        fourthThreeLayoutParams = (FrameLayout.LayoutParams) fourth_three.getLayoutParams();
        fourthFourLayoutParams = (FrameLayout.LayoutParams) fourth_four.getLayoutParams();
        fourthFiveLayoutParams = (FrameLayout.LayoutParams) fourth_five.getLayoutParams();
        //第五个座位
        fifthOneLayoutParams = (FrameLayout.LayoutParams) fifth_one.getLayoutParams();
        fifthTwoLayoutParams = (FrameLayout.LayoutParams) fifth_two.getLayoutParams();
        fifthThreeLayoutParams = (FrameLayout.LayoutParams) fifth_three.getLayoutParams();
        fifthFourLayoutParams = (FrameLayout.LayoutParams) fifth_four.getLayoutParams();
        fifthFiveLayoutParams = (FrameLayout.LayoutParams) fifth_five.getLayoutParams();

        firstOneLayoutParams.setMargins(0, 0, 0, 0);
        firstTwoLayoutParams.setMargins(0, 0, 0, 0);
        firstThreeLayoutParams.setMargins(0, 0, 0, 0);
        firstFourLayoutParams.setMargins(0, 0, 0, 0);
        firstFiveLayoutParams.setMargins(0, 0, 0, 0);

        secondOneLayoutParams.setMargins(0, 0, 0, 0);
        secondTwoLayoutParams.setMargins(0, 0, 0, 0);
        secondThreeLayoutParams.setMargins(0, 0, 0, 0);
        secondFourLayoutParams.setMargins(0, 0, 0, 0);
        secondFiveLayoutParams.setMargins(0, 0, 0, 0);

        thirdOneLayoutParams.setMargins(0, 0, 0, 0);
        thirdTwoLayoutParams.setMargins(0, 0, 0, 0);
        thirdThreeLayoutParams.setMargins(0, 0, 0, 0);
        thirdFourLayoutParams.setMargins(0, 0, 0, 0);
        thirdFiveLayoutParams.setMargins(0, 0, 0, 0);

        fourthOneLayoutParams.setMargins(0, 0, 0, 0);
        fourthTwoLayoutParams.setMargins(0, 0, 0, 0);
        fourthThreeLayoutParams.setMargins(0, 0, 0, 0);
        fourthFourLayoutParams.setMargins(0, 0, 0, 0);
        fourthFiveLayoutParams.setMargins(0, 0, 0, 0);

        fifthOneLayoutParams.setMargins(0, 0, 0, 0);
        fifthTwoLayoutParams.setMargins(0, 0, 0, 0);
        fifthThreeLayoutParams.setMargins(0, 0, 0, 0);
        fifthFourLayoutParams.setMargins(0, 0, 0, 0);
        fifthFiveLayoutParams.setMargins(0, 0, 0, 0);
        first_one.setImageResource(CardUtil.cards[55]);
        first_two.setImageResource(CardUtil.cards[55]);
        first_three.setImageResource(CardUtil.cards[55]);
        first_four.setImageResource(CardUtil.cards[55]);
        first_five.setImageResource(CardUtil.cards[55]);

        second_one.setImageResource(CardUtil.cards[55]);
        second_two.setImageResource(CardUtil.cards[55]);
        second_three.setImageResource(CardUtil.cards[55]);
        second_four.setImageResource(CardUtil.cards[55]);
        second_five.setImageResource(CardUtil.cards[55]);

        third_one.setImageResource(CardUtil.cards[55]);
        third_two.setImageResource(CardUtil.cards[55]);
        third_three.setImageResource(CardUtil.cards[55]);
        third_four.setImageResource(CardUtil.cards[55]);
        third_five.setImageResource(CardUtil.cards[55]);

        fourth_one.setImageResource(CardUtil.cards[55]);
        fourth_two.setImageResource(CardUtil.cards[55]);
        fourth_three.setImageResource(CardUtil.cards[55]);
        fourth_four.setImageResource(CardUtil.cards[55]);
        fourth_five.setImageResource(CardUtil.cards[55]);

        fifth_one.setImageResource(CardUtil.cards[55]);
        fifth_two.setImageResource(CardUtil.cards[55]);
        fifth_three.setImageResource(CardUtil.cards[55]);
        fifth_four.setImageResource(CardUtil.cards[55]);
        fifth_five.setImageResource(CardUtil.cards[55]);

        iv_second_escrow.setImageResource(CardUtil.cards[55]);
        iv_third_escrow.setImageResource(CardUtil.cards[55]);
        iv_fourth_escrow.setImageResource(CardUtil.cards[55]);
        iv_fifth_escrow.setImageResource(CardUtil.cards[55]);

        iv_get_card.setImageResource(CardUtil.cards[55]);
        tv_get_card.setText("");

        iv_next_player.setImageResource(CardUtil.cards[55]);
        tv_next_player.setText("");

        tv_second_escrow.setText("");
        tv_third_escrow.setText("");
        tv_fourth_escrow.setText("");
        tv_fifth_escrow.setText("");
    }

    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        if (keyCode == KeyEvent.KEYCODE_BACK && event.getAction() == KeyEvent.ACTION_DOWN) {
            if ("0".equals(selfSeatNo)) {
                if (settlementStatus) {
//                    AlertShow.dialog = ProgressDialog.show(this, null, "筹码结算中...");
                    //庄家才能实现关闭房间
                    Intent settlementIntent = new Intent(CustomAction.SERVICE_ACTION);
                    Map<String, Object> map = new HashMap<>();
                    map.put("reqType", "settlementReq");
                    map.put("roomId", selfRoomId);
                    map.put("bankerChip", selfChip);
                    settlementIntent.putExtra("request", JSONObject.toJSON(map).toString());
                    sendBroadcast(settlementIntent);

                    banker_settlement = (LinearLayout) UserRoomActivity.this.getLayoutInflater().inflate(R.layout.banker_settlement, null);

                    return_main_banker = banker_settlement.findViewById(R.id.return_main_banker);
                    banker_chip_banker = banker_settlement.findViewById(R.id.banker_chip_banker);
                    banker_chip_banker.setText(selfChip + "");
                    return_main_banker.setOnClickListener(UserRoomActivity.this);
                    bankerDialog = new AlertDialog.Builder(UserRoomActivity.this)
                            .setView(banker_settlement)
                            .create();
                    bankerDialog.setCancelable(false);
                } else {
                    Toast.makeText(this, "牌局尚未完成", Toast.LENGTH_SHORT).show();
                }
            } else {
                Toast.makeText(this, "请庄家指令", Toast.LENGTH_SHORT).show();
            }

        }
        return false;
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        if (bankerDialog!=null){
            bankerDialog.dismiss();
        }
        if (settlementDialog!=null){
            settlementDialog.dismiss();
        }
        unregisterReceiver(userRoomReceiver);
    }

    public class UserRoomReceiver extends BroadcastReceiver {

        @Override
        public void onReceive(Context context, Intent intent) {
            try {

                String respType = intent.getStringExtra("getSeat");
                if ("901".equals(respType)) {
                    //当前加入房间的玩家，如果前面有已经加入房间的玩家，则获取他们的信息
                    seats = intent.getStringExtra("seatList");
                    List<Seat> seatList = JSONObject.parseArray(seats, Seat.class);
                    selfUserName = seatList.get(0).getUserName();
                    selfSeatNo = seatList.get(0).getSeatNo();//新加入房间玩家的座位号
                    selfSeatNoNum = Long.parseLong(selfSeatNo);
                    tv_first.setText(selfUserName);//新加入房间玩家的昵称

                    //判断自己相对的其他玩家分别在哪个座位，并且判断哪个位置是房主是房主
                    if (seatList.size() == 1) {
                        first_banker.setImageResource(R.drawable.battle100_21);
                    }
                    if (seatList.size() == 2) {
                        tv_fifth.setText(seatList.get(1).getUserName());
                        fifth_banker.setImageResource(R.drawable.battle100_21);
                    }
                    if (seatList.size() == 3) {
                        tv_fourth.setText(seatList.get(1).getUserName());
                        fourth_banker.setImageResource(R.drawable.battle100_21);
                        tv_fifth.setText(seatList.get(2).getUserName());
                    }
                    if (seatList.size() == 4) {
                        tv_third.setText(seatList.get(1).getUserName());
                        third_banker.setImageResource(R.drawable.battle100_21);
                        tv_fourth.setText(seatList.get(2).getUserName());
                        tv_fifth.setText(seatList.get(3).getUserName());
                    }
                    if (seatList.size() == 5) {
                        tv_second.setText(seatList.get(1).getUserName());
                        second_banker.setImageResource(R.drawable.battle100_21);
                        tv_third.setText(seatList.get(2).getUserName());
                        tv_fourth.setText(seatList.get(3).getUserName());
                        tv_fifth.setText(seatList.get(4).getUserName());
                    }
                } else if ("902".equals(respType)) {
                    //获得新加入房间的玩家的座位信息
                    String seat = intent.getStringExtra("seat");
                    JSONObject seatJson = JSONObject.parseObject(seat);
                    String roomId = seatJson.getString("roomId");
                    joinUserName = seatJson.getString("userName");
                    joinSeatNo = seatJson.getString("seatNo");
                    long joinSeatNoNum = Long.parseLong(joinSeatNo);


                    //判断结算筹码的玩家姓名顺序
                    if ("1".equals(joinSeatNo)) {
                        secondMap.put("playerName", joinUserName);
                    } else if ("2".equals(joinSeatNo)) {
                        thirdMap.put("playerName", joinUserName);
                    } else if ("3".equals(joinSeatNo)) {
                        fourthMap.put("playerName", joinUserName);
                    } else if ("4".equals(joinSeatNo)) {
                        fifthMap.put("playerName", joinUserName);
                    }

                    //报错Caused by: java.lang.NumberFormatException: For input string: ""
                    //原因：因为测试的时候用同一个手机，退出房间再次进入房间，导致没有初始化，用同一个手机测试时需要退出app再重新联网进行测试
                    if (joinSeatNoNum - selfSeatNoNum == 1) {
                        tv_second.setText(joinUserName);
                    }
                    if (joinSeatNoNum - selfSeatNoNum == 2) {
                        tv_third.setText(joinUserName);
                    }
                    if (joinSeatNoNum - selfSeatNoNum == 3) {
                        tv_fourth.setText(joinUserName);
                    }
                    if (joinSeatNoNum - selfSeatNoNum == 4) {
                        tv_fifth.setText(joinUserName);
                    }
                } else if ("001".equals(respType)) {
                    if ("0".equals(selfSeatNo)) {
                        //通知房主可以立即开始
                        iv_deal.setImageResource(R.drawable.select_deal);
                        iv_deal.setClickable(true);
                        //显示指针指向相对位置,绝对位置是 0 时，相对位置是 0:first
                        iv_pointer_first.setImageResource(R.drawable.pointer_top);
                    } else if ("1".equals(selfSeatNo)) {
                        //显示指针指向相对位置,绝对位置是 1 时，相对位置是 4:fifth
                        iv_pointer_fifth.setImageResource(R.drawable.pointer);
                    } else if ("2".equals(selfSeatNo)) {
                        //显示指针指向相对位置,绝对位置是 2 时，相对位置是 3:fourth
                        iv_pointer_fourth.setImageResource(R.drawable.pointer);
                    } else if ("3".equals(selfSeatNo)) {
                        //显示指针指向相对位置,绝对位置是 3 时，相对位置是 2:third
                        iv_pointer_third.setImageResource(R.drawable.pointer);
                    } else if ("4".equals(selfSeatNo)) {
                        //显示指针指向相对位置,绝对位置是 4 时，相对位置是 1:second
                        iv_pointer_second.setImageResource(R.drawable.pointer);
                    }
                } else if ("009".equals(respType)) {
                    initCards();
                    selfCards.clear();

                    new CountDownTimer(8 * 1000, 1000) {
                        @Override
                        public void onTick(long millisUntilFinished) {
                            tv_show_time.setText(millisUntilFinished / 1000 + "秒后发牌");
                            SpannableStringBuilder builder = new SpannableStringBuilder(tv_show_time.getText().toString());
                            ForegroundColorSpan redSpan = new ForegroundColorSpan(Color.RED);
                            builder.setSpan(redSpan, 0, 1, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
                            tv_show_time.setText(builder);
                        }

                        @Override
                        public void onFinish() {
                            tv_show_time.setText("");
                        }
                    }.start();

                    //房主筹码初始化的情况
                    if ("0".equals(selfSeatNo)) {
                        initBankerChip();
                    } else {
                        initSelectEscrow();

                    }
                } else if ("010".equals(respType)) {
                    String seatNo = intent.getStringExtra("seatNo");
                    String escrow = intent.getStringExtra("escrow");
                    int relativeSeatNo = getRelativeSeatNo(Integer.parseInt(seatNo));
                    if (1 == relativeSeatNo) {
                        iv_second_escrow.setImageResource(R.drawable.bet_room_asset_description_pop_right_coins);
                        tv_second_escrow.setText(escrow);
                    } else if (2 == relativeSeatNo) {
                        iv_third_escrow.setImageResource(R.drawable.bet_room_asset_description_pop_right_coins);
                        tv_third_escrow.setText(escrow);
                    } else if (3 == relativeSeatNo) {
                        iv_fourth_escrow.setImageResource(R.drawable.bet_room_asset_description_pop_right_coins);
                        tv_fourth_escrow.setText(escrow);
                    } else if (4 == relativeSeatNo) {
                        iv_fifth_escrow.setImageResource(R.drawable.bet_room_asset_description_pop_right_coins);
                        tv_fifth_escrow.setText(escrow);
                    }
                } else if ("002".equals(respType)) {
                    //获取自己随机获得的牌，其他玩家获取的牌看不到，除非有的玩家获得的牌型是A+A,A+J,A+Q,A+K
                    String dealCards = intent.getStringExtra("dealCards");
                    List<Integer> cardList = JSONObject.parseArray(dealCards, Integer.class);
                    //第一个座位
                    first_one.setImageResource(CardUtil.cards[cardList.get(0)]);
                    selfCards.add(cardList.get(0));
                    firstOneLayoutParams.rightMargin = 20;
                    first_one.setLayoutParams(firstOneLayoutParams);

                    first_two.setImageResource(CardUtil.cards[cardList.get(1)]);
                    selfCards.add(cardList.get(1));
                    firstTwoLayoutParams.leftMargin = 20;
                    first_two.setLayoutParams(firstTwoLayoutParams);

                } else if ("003".equals(respType)) {
                    String otherSeatNo = intent.getStringExtra("otherSeatNo");
                    String dealCards = intent.getStringExtra("dealCards");
                    List<Integer> cardList = JSONObject.parseArray(dealCards, Integer.class);

                    //以下方法是以相对座位判断用户位置，减少代码
                    if (1 == getRelativeSeatNo(Integer.parseInt(otherSeatNo))) {
                        secondEye = false;
                        //第二个座位
                        second_one.setImageResource(CardUtil.cards[cardList.get(0)]);
                        secondOneLayoutParams.rightMargin = 20;
                        second_one.setLayoutParams(secondOneLayoutParams);

                        second_two.setImageResource(CardUtil.cards[cardList.get(1)]);
                        secondTwoLayoutParams.leftMargin = 20;
                        second_two.setLayoutParams(secondTwoLayoutParams);
                    } else if (2 == getRelativeSeatNo(Integer.parseInt(otherSeatNo))) {
                        thirdEye = false;
                        //第三个座位
                        third_one.setImageResource(CardUtil.cards[cardList.get(0)]);
                        thirdOneLayoutParams.rightMargin = 20;
                        third_one.setLayoutParams(thirdOneLayoutParams);

                        third_two.setImageResource(CardUtil.cards[cardList.get(1)]);
                        thirdTwoLayoutParams.leftMargin = 20;
                        third_two.setLayoutParams(thirdTwoLayoutParams);
                    } else if (3 == getRelativeSeatNo(Integer.parseInt(otherSeatNo))) {
                        fourthEye = false;
                        //第四个座位
                        fourth_one.setImageResource(CardUtil.cards[cardList.get(0)]);
                        fourthOneLayoutParams.rightMargin = 20;
                        fourth_one.setLayoutParams(fourthOneLayoutParams);

                        fourth_two.setImageResource(CardUtil.cards[cardList.get(1)]);
                        fourthTwoLayoutParams.leftMargin = 20;
                        fourth_two.setLayoutParams(fourthTwoLayoutParams);
                    } else if (4 == getRelativeSeatNo(Integer.parseInt(otherSeatNo))) {
                        fifthEye = false;
                        //第五个座位
                        fifth_one.setImageResource(CardUtil.cards[cardList.get(0)]);
                        fifthOneLayoutParams.rightMargin = 20;
                        fifth_one.setLayoutParams(fifthOneLayoutParams);

                        fifth_two.setImageResource(CardUtil.cards[cardList.get(1)]);
                        fifthTwoLayoutParams.leftMargin = 20;
                        fifth_two.setLayoutParams(fifthTwoLayoutParams);
                    }
                    if (selfSeatNo.equals(otherSeatNo) && "0".equals(selfSeatNo)) {
                        settlementStatus = true;

                        iv_deal.setImageResource(R.drawable.select_deal);
                        iv_deal.setClickable(true);

                        second_eye.setImageResource(CardUtil.cards[55]);
                        third_eye.setImageResource(CardUtil.cards[55]);
                        fourth_eye.setImageResource(CardUtil.cards[55]);
                        fifth_eye.setImageResource(CardUtil.cards[55]);
                        second_eye.setClickable(false);
                        third_eye.setClickable(false);
                        fourth_eye.setClickable(false);
                        fifth_eye.setClickable(false);
                    }
                } else if ("004".equals(respType)) {
                    String otherSeatNo = intent.getStringExtra("otherSeatNo");
                    int relativeSeatNo = getRelativeSeatNo(Integer.parseInt(otherSeatNo));
                    if (1 == relativeSeatNo) {
                        //第二个座位
                        second_one.setImageResource(CardUtil.cards[54]);
                        secondOneLayoutParams.rightMargin = 20;
                        second_one.setLayoutParams(secondOneLayoutParams);

                        second_two.setImageResource(CardUtil.cards[54]);
                        secondTwoLayoutParams.leftMargin = 20;
                        second_two.setLayoutParams(secondTwoLayoutParams);
                    } else if (2 == relativeSeatNo) {
                        //第三个座位
                        third_one.setImageResource(CardUtil.cards[54]);
                        thirdOneLayoutParams.rightMargin = 20;
                        third_one.setLayoutParams(thirdOneLayoutParams);

                        third_two.setImageResource(CardUtil.cards[54]);
                        thirdTwoLayoutParams.leftMargin = 20;
                        third_two.setLayoutParams(thirdTwoLayoutParams);
                    } else if (3 == relativeSeatNo) {
                        //第四个座位
                        fourth_one.setImageResource(CardUtil.cards[54]);
                        fourthOneLayoutParams.rightMargin = 20;
                        fourth_one.setLayoutParams(fourthOneLayoutParams);

                        fourth_two.setImageResource(CardUtil.cards[54]);
                        fourthTwoLayoutParams.leftMargin = 20;
                        fourth_two.setLayoutParams(fourthTwoLayoutParams);
                    } else if (4 == relativeSeatNo) {
                        //第五个座位
                        fifth_one.setImageResource(CardUtil.cards[54]);
                        fifthOneLayoutParams.rightMargin = 20;
                        fifth_one.setLayoutParams(fifthOneLayoutParams);

                        fifth_two.setImageResource(CardUtil.cards[54]);
                        fifthTwoLayoutParams.leftMargin = 20;
                        fifth_two.setLayoutParams(fifthTwoLayoutParams);
                    }
                } else if ("005".equals(respType)) {
                    pointerSeatNo = intent.getStringExtra("pointerSeatNo");
                    //懒得判断，每次都清除所有指针
                    iv_pointer_first.setImageResource(CardUtil.cards[55]);
                    iv_pointer_second.setImageResource(CardUtil.cards[55]);
                    iv_pointer_third.setImageResource(CardUtil.cards[55]);
                    iv_pointer_fourth.setImageResource(CardUtil.cards[55]);
                    iv_pointer_fifth.setImageResource(CardUtil.cards[55]);
                    iv_get_card.setImageResource(CardUtil.cards[55]);
                    tv_get_card.setText("");
                    iv_get_card.setClickable(false);
                    iv_next_player.setImageResource(CardUtil.cards[55]);
                    tv_next_player.setText("");
                    iv_next_player.setClickable(false);
                    int relativePointerSeatNo = getRelativeSeatNo(Integer.parseInt(pointerSeatNo));
                    if (1 == relativePointerSeatNo) {
                        iv_pointer_second.setImageResource(R.drawable.pointer);
                    } else if (2 == relativePointerSeatNo) {
                        iv_pointer_third.setImageResource(R.drawable.pointer);
                    } else if (3 == relativePointerSeatNo) {
                        iv_pointer_fourth.setImageResource(R.drawable.pointer);
                    } else if (4 == relativePointerSeatNo) {
                        iv_pointer_fifth.setImageResource(R.drawable.pointer);
                    }

                    //只要指针指向自己就可以摸牌 显示摸牌按钮
                    if (pointerSeatNo.equals(selfSeatNo)) {
                        iv_pointer_first.setImageResource(R.drawable.pointer_top);
                        iv_get_card.setImageResource(R.drawable.select_get_card);
                        tv_get_card.setText("摸牌");
                        iv_get_card.setClickable(true);
                        //需要指针指向自己时，符合条件才可以点击下一家或者房主进行开牌，这时候每个玩家有且只有两张牌
                        //有一张A，且两张牌的值大于等于6，A转换成11点的时候，事实是大于等于16点
                        if ((CardUtil.getACardCount(selfCards) == 1 && CardUtil.getDealCardValue(selfCards) >= 6)
                                //手中的牌没有A，但是两张牌的值加起来大于等于16
                                || (CardUtil.getACardCount(selfCards) == 0 && CardUtil.getFirstSizeCardValue(selfCards) >= 16) && selfCards.size() == 2) {

                            iv_next_player.setImageResource(R.drawable.select_next);
                            tv_next_player.setText("下一家");
                            iv_next_player.setClickable(true);

                            if ("0".equals(selfSeatNo)) {
                                iv_next_player.setImageResource(R.drawable.select_eye);
                                tv_next_player.setText("全部开牌");
                                iv_next_player.setClickable(true);

                                if ("2".equals(userLimit)) {
                                    if (secondEye) {
                                        second_eye.setImageResource(R.drawable.select_eye);
                                        second_eye.setClickable(true);
                                    }

                                } else if ("3".equals(userLimit)) {
                                    if (secondEye) {
                                        second_eye.setImageResource(R.drawable.select_eye);
                                        second_eye.setClickable(true);
                                    }
                                    if (thirdEye) {
                                        third_eye.setImageResource(R.drawable.select_eye);
                                        third_eye.setClickable(true);
                                    }

                                } else if ("4".equals(userLimit)) {
                                    if (secondEye) {
                                        second_eye.setImageResource(R.drawable.select_eye);
                                        second_eye.setClickable(true);
                                    }
                                    if (thirdEye) {
                                        third_eye.setImageResource(R.drawable.select_eye);
                                        third_eye.setClickable(true);
                                    }
                                    if (fourthEye) {
                                        fourth_eye.setImageResource(R.drawable.select_eye);
                                        fourth_eye.setClickable(true);
                                    }

                                } else if ("5".equals(userLimit)) {
                                    if (secondEye) {
                                        second_eye.setImageResource(R.drawable.select_eye);
                                        second_eye.setClickable(true);
                                    }
                                    if (thirdEye) {
                                        third_eye.setImageResource(R.drawable.select_eye);
                                        third_eye.setClickable(true);
                                    }
                                    if (fourthEye) {
                                        fourth_eye.setImageResource(R.drawable.select_eye);
                                        fourth_eye.setClickable(true);
                                    }
                                    if (fifthEye) {
                                        fifth_eye.setImageResource(R.drawable.select_eye);
                                        fifth_eye.setClickable(true);
                                    }

                                }
                            }
                        }
                    }

                } else if ("006".equals(respType)) {
                    String seatNo = intent.getStringExtra("seatNo");
                    List<Integer> cardList = JSONObject.parseArray(intent.getStringExtra("cardList"), Integer.class);
                    if (!cardList.isEmpty()) {
                        String cardCount = cardList.size() + "";
                        if (selfSeatNo.equals(seatNo)) {
                            iv_get_card.setImageResource(CardUtil.cards[55]);
                            tv_get_card.setText("");
                            iv_get_card.setClickable(false);
                            tv_next_player.setText("");
                            iv_next_player.setImageResource(CardUtil.cards[55]);
                            iv_next_player.setClickable(false);
                            if ("3".equals(cardCount)) {
                                //第一个座位
                                firstOneLayoutParams.rightMargin = 40;
                                first_one.setLayoutParams(firstOneLayoutParams);

                                firstTwoLayoutParams.rightMargin = 20;
                                first_two.setLayoutParams(firstTwoLayoutParams);

                                first_three.setImageResource(CardUtil.cards[cardList.get(2)]);
                                firstThreeLayoutParams.leftMargin = 40;
                                first_three.setLayoutParams(firstThreeLayoutParams);
                            } else if ("4".equals(cardCount)) {
                                //第一个座位
                                firstOneLayoutParams.rightMargin = 60;
                                first_one.setLayoutParams(firstOneLayoutParams);

                                firstTwoLayoutParams.rightMargin = 40;
                                first_two.setLayoutParams(firstTwoLayoutParams);

                                firstThreeLayoutParams.leftMargin = 20;
                                first_three.setLayoutParams(firstThreeLayoutParams);

                                first_four.setImageResource(CardUtil.cards[cardList.get(3)]);
                                firstFourLayoutParams.leftMargin = 60;
                                first_four.setLayoutParams(firstFourLayoutParams);
                            } else if ("5".equals(cardCount)) {
                                //第一个座位
                                firstOneLayoutParams.rightMargin = 80;
                                first_one.setLayoutParams(firstOneLayoutParams);

                                firstTwoLayoutParams.rightMargin = 60;
                                first_two.setLayoutParams(firstTwoLayoutParams);

                                firstThreeLayoutParams.rightMargin = 20;
                                first_three.setLayoutParams(firstThreeLayoutParams);

                                firstFourLayoutParams.leftMargin = 40;
                                first_four.setLayoutParams(firstFourLayoutParams);

                                first_five.setImageResource(CardUtil.cards[cardList.get(4)]);
                                firstFiveLayoutParams.leftMargin = 80;
                                first_five.setLayoutParams(firstFiveLayoutParams);
                            }
                            if ("0".equals(selfSeatNo)) {
                                settlementStatus = true;
                                iv_deal.setImageResource(R.drawable.select_deal);
                                iv_deal.setClickable(true);
                                second_eye.setImageResource(CardUtil.cards[55]);
                                third_eye.setImageResource(CardUtil.cards[55]);
                                fourth_eye.setImageResource(CardUtil.cards[55]);
                                fifth_eye.setImageResource(CardUtil.cards[55]);
                                second_eye.setClickable(false);
                                third_eye.setClickable(false);
                                fourth_eye.setClickable(false);
                                fifth_eye.setClickable(false);
                            }
                        }

                        int relativeSeatNo = getRelativeSeatNo(Integer.parseInt(seatNo));

                        if (1 == relativeSeatNo) {
                            secondEye = false;
                            //第二个座位
                            second_one.setImageResource(CardUtil.cards[cardList.get(0)]);
                            secondOneLayoutParams.rightMargin = 20;
                            second_one.setLayoutParams(secondOneLayoutParams);

                            second_two.setImageResource(CardUtil.cards[cardList.get(1)]);
                            secondTwoLayoutParams.leftMargin = 20;
                            second_two.setLayoutParams(secondTwoLayoutParams);
                            //第二个座位
                            if ("3".equals(cardCount)) {
                                //第二个座位
                                secondOneLayoutParams.rightMargin = 40;
                                second_one.setLayoutParams(secondOneLayoutParams);

                                secondTwoLayoutParams.rightMargin = 20;
                                second_two.setLayoutParams(secondTwoLayoutParams);

                                second_three.setImageResource(CardUtil.cards[cardList.get(2)]);
                                secondThreeLayoutParams.leftMargin = 40;
                                second_three.setLayoutParams(secondThreeLayoutParams);
                            } else if ("4".equals(cardCount)) {
                                //第二个座位
                                secondOneLayoutParams.rightMargin = 40;
                                second_one.setLayoutParams(secondOneLayoutParams);

                                secondTwoLayoutParams.rightMargin = 20;
                                second_two.setLayoutParams(secondTwoLayoutParams);

                                second_three.setImageResource(CardUtil.cards[cardList.get(2)]);
                                secondThreeLayoutParams.leftMargin = 40;
                                second_three.setLayoutParams(secondThreeLayoutParams);

                                //第二个座位
                                secondOneLayoutParams.rightMargin = 60;
                                second_one.setLayoutParams(secondOneLayoutParams);

                                secondTwoLayoutParams.rightMargin = 40;
                                second_two.setLayoutParams(secondTwoLayoutParams);

                                secondThreeLayoutParams.leftMargin = 20;
                                second_three.setLayoutParams(secondThreeLayoutParams);

                                second_four.setImageResource(CardUtil.cards[cardList.get(3)]);
                                secondFourLayoutParams.leftMargin = 60;
                                second_four.setLayoutParams(secondFourLayoutParams);
                            } else if ("5".equals(cardCount)) {
                                //第二个座位
                                secondOneLayoutParams.rightMargin = 40;
                                second_one.setLayoutParams(secondOneLayoutParams);

                                secondTwoLayoutParams.rightMargin = 20;
                                second_two.setLayoutParams(secondTwoLayoutParams);

                                second_three.setImageResource(CardUtil.cards[cardList.get(2)]);
                                secondThreeLayoutParams.leftMargin = 40;
                                second_three.setLayoutParams(secondThreeLayoutParams);

                                //第二个座位
                                secondOneLayoutParams.rightMargin = 60;
                                second_one.setLayoutParams(secondOneLayoutParams);

                                secondTwoLayoutParams.rightMargin = 40;
                                second_two.setLayoutParams(secondTwoLayoutParams);

                                secondThreeLayoutParams.leftMargin = 20;
                                second_three.setLayoutParams(secondThreeLayoutParams);

                                second_four.setImageResource(CardUtil.cards[cardList.get(3)]);
                                secondFourLayoutParams.leftMargin = 60;
                                second_four.setLayoutParams(secondFourLayoutParams);
                                //第二个座位
                                secondOneLayoutParams.rightMargin = 80;
                                second_one.setLayoutParams(secondOneLayoutParams);

                                secondTwoLayoutParams.rightMargin = 60;
                                second_two.setLayoutParams(secondTwoLayoutParams);

                                secondThreeLayoutParams.rightMargin = 20;
                                second_three.setLayoutParams(secondThreeLayoutParams);

                                secondFourLayoutParams.leftMargin = 40;
                                second_four.setLayoutParams(secondFourLayoutParams);

                                second_five.setImageResource(CardUtil.cards[cardList.get(4)]);
                                secondFiveLayoutParams.leftMargin = 80;
                                second_five.setLayoutParams(secondFiveLayoutParams);
                            }
                        } else if (2 == relativeSeatNo) {
                            thirdEye = false;
                            //第三个座位
                            third_one.setImageResource(CardUtil.cards[cardList.get(0)]);
                            thirdOneLayoutParams.rightMargin = 20;
                            third_one.setLayoutParams(thirdOneLayoutParams);

                            third_two.setImageResource(CardUtil.cards[cardList.get(1)]);
                            thirdTwoLayoutParams.leftMargin = 20;
                            third_two.setLayoutParams(thirdTwoLayoutParams);
                            //第三个座位
                            if ("3".equals(cardCount)) {
                                //第三个座位
                                thirdOneLayoutParams.rightMargin = 40;
                                third_one.setLayoutParams(thirdOneLayoutParams);

                                thirdTwoLayoutParams.rightMargin = 20;
                                third_two.setLayoutParams(thirdTwoLayoutParams);

                                third_three.setImageResource(CardUtil.cards[cardList.get(2)]);
                                thirdThreeLayoutParams.leftMargin = 40;
                                third_three.setLayoutParams(thirdThreeLayoutParams);

                            } else if ("4".equals(cardCount)) {
                                //第三个座位
                                thirdOneLayoutParams.rightMargin = 40;
                                third_one.setLayoutParams(thirdOneLayoutParams);

                                thirdTwoLayoutParams.rightMargin = 20;
                                third_two.setLayoutParams(thirdTwoLayoutParams);

                                third_three.setImageResource(CardUtil.cards[cardList.get(2)]);
                                thirdThreeLayoutParams.leftMargin = 40;
                                third_three.setLayoutParams(thirdThreeLayoutParams);
                                //第三个座位
                                thirdOneLayoutParams.rightMargin = 60;
                                third_one.setLayoutParams(thirdOneLayoutParams);

                                thirdTwoLayoutParams.rightMargin = 40;
                                third_two.setLayoutParams(thirdTwoLayoutParams);

                                thirdThreeLayoutParams.leftMargin = 20;
                                third_three.setLayoutParams(thirdThreeLayoutParams);

                                third_four.setImageResource(CardUtil.cards[cardList.get(3)]);
                                thirdFourLayoutParams.leftMargin = 60;
                                third_four.setLayoutParams(thirdFourLayoutParams);
                            } else if ("5".equals(cardCount)) {
                                //第三个座位
                                thirdOneLayoutParams.rightMargin = 40;
                                third_one.setLayoutParams(thirdOneLayoutParams);

                                thirdTwoLayoutParams.rightMargin = 20;
                                third_two.setLayoutParams(thirdTwoLayoutParams);

                                third_three.setImageResource(CardUtil.cards[cardList.get(2)]);
                                thirdThreeLayoutParams.leftMargin = 40;
                                third_three.setLayoutParams(thirdThreeLayoutParams);
                                //第三个座位
                                thirdOneLayoutParams.rightMargin = 60;
                                third_one.setLayoutParams(thirdOneLayoutParams);

                                thirdTwoLayoutParams.rightMargin = 40;
                                third_two.setLayoutParams(thirdTwoLayoutParams);

                                thirdThreeLayoutParams.leftMargin = 20;
                                third_three.setLayoutParams(thirdThreeLayoutParams);

                                third_four.setImageResource(CardUtil.cards[cardList.get(3)]);
                                thirdFourLayoutParams.leftMargin = 60;
                                third_four.setLayoutParams(thirdFourLayoutParams);
                                //第三个座位
                                thirdOneLayoutParams.rightMargin = 80;
                                third_one.setLayoutParams(thirdOneLayoutParams);

                                thirdTwoLayoutParams.rightMargin = 60;
                                third_two.setLayoutParams(thirdTwoLayoutParams);

                                thirdThreeLayoutParams.rightMargin = 20;
                                third_three.setLayoutParams(thirdThreeLayoutParams);

                                thirdFourLayoutParams.leftMargin = 40;
                                third_four.setLayoutParams(thirdFourLayoutParams);

                                third_five.setImageResource(CardUtil.cards[cardList.get(4)]);
                                thirdFiveLayoutParams.leftMargin = 80;
                                third_five.setLayoutParams(thirdFiveLayoutParams);
                            }
                        } else if (3 == relativeSeatNo) {
                            fourthEye = false;
                            //第四个座位
                            fourth_one.setImageResource(CardUtil.cards[cardList.get(0)]);
                            fourthOneLayoutParams.rightMargin = 20;
                            fourth_one.setLayoutParams(fourthOneLayoutParams);

                            fourth_two.setImageResource(CardUtil.cards[cardList.get(1)]);
                            fourthTwoLayoutParams.leftMargin = 20;
                            fourth_two.setLayoutParams(fourthTwoLayoutParams);
                            //第四个座位
                            if ("3".equals(cardCount)) {
                                //第四个座位
                                fourthOneLayoutParams.rightMargin = 40;
                                fourth_one.setLayoutParams(fourthOneLayoutParams);

                                fourthTwoLayoutParams.rightMargin = 20;
                                fourth_two.setLayoutParams(fourthTwoLayoutParams);

                                fourth_three.setImageResource(CardUtil.cards[cardList.get(2)]);
                                fourthThreeLayoutParams.leftMargin = 40;
                                fourth_three.setLayoutParams(fourthThreeLayoutParams);
                            } else if ("4".equals(cardCount)) {
                                //第四个座位
                                fourthOneLayoutParams.rightMargin = 40;
                                fourth_one.setLayoutParams(fourthOneLayoutParams);

                                fourthTwoLayoutParams.rightMargin = 20;
                                fourth_two.setLayoutParams(fourthTwoLayoutParams);

                                fourth_three.setImageResource(CardUtil.cards[cardList.get(2)]);
                                fourthThreeLayoutParams.leftMargin = 40;
                                fourth_three.setLayoutParams(fourthThreeLayoutParams);
                                //第四个座位
                                fourthOneLayoutParams.rightMargin = 60;
                                fourth_one.setLayoutParams(fourthOneLayoutParams);

                                fourthTwoLayoutParams.rightMargin = 40;
                                fourth_two.setLayoutParams(fourthTwoLayoutParams);

                                fourthThreeLayoutParams.leftMargin = 20;
                                fourth_three.setLayoutParams(fourthThreeLayoutParams);

                                fourth_four.setImageResource(CardUtil.cards[cardList.get(3)]);
                                fourthFourLayoutParams.leftMargin = 60;
                                fourth_four.setLayoutParams(fourthFourLayoutParams);

                            } else if ("5".equals(cardCount)) {
                                //第四个座位
                                fourthOneLayoutParams.rightMargin = 40;
                                fourth_one.setLayoutParams(fourthOneLayoutParams);

                                fourthTwoLayoutParams.rightMargin = 20;
                                fourth_two.setLayoutParams(fourthTwoLayoutParams);

                                fourth_three.setImageResource(CardUtil.cards[cardList.get(2)]);
                                fourthThreeLayoutParams.leftMargin = 40;
                                fourth_three.setLayoutParams(fourthThreeLayoutParams);
                                //第四个座位
                                fourthOneLayoutParams.rightMargin = 60;
                                fourth_one.setLayoutParams(fourthOneLayoutParams);

                                fourthTwoLayoutParams.rightMargin = 40;
                                fourth_two.setLayoutParams(fourthTwoLayoutParams);

                                fourthThreeLayoutParams.leftMargin = 20;
                                fourth_three.setLayoutParams(fourthThreeLayoutParams);

                                fourth_four.setImageResource(CardUtil.cards[cardList.get(3)]);
                                fourthFourLayoutParams.leftMargin = 60;
                                fourth_four.setLayoutParams(fourthFourLayoutParams);
                                //第四个座位
                                fourthOneLayoutParams.rightMargin = 80;
                                fourth_one.setLayoutParams(fourthOneLayoutParams);

                                fourthTwoLayoutParams.rightMargin = 60;
                                fourth_two.setLayoutParams(fourthTwoLayoutParams);

                                fourthThreeLayoutParams.rightMargin = 20;
                                fourth_three.setLayoutParams(fourthThreeLayoutParams);

                                fourthFourLayoutParams.leftMargin = 40;
                                fourth_four.setLayoutParams(fourthFourLayoutParams);

                                fourth_five.setImageResource(CardUtil.cards[cardList.get(4)]);
                                fourthFiveLayoutParams.leftMargin = 80;
                                fourth_five.setLayoutParams(fourthFiveLayoutParams);
                            }
                        } else if (4 == relativeSeatNo) {
                            fifthEye = false;
                            //第五个座位
                            fifth_one.setImageResource(CardUtil.cards[cardList.get(0)]);
                            fifthOneLayoutParams.rightMargin = 20;
                            fifth_one.setLayoutParams(fifthOneLayoutParams);

                            fifth_two.setImageResource(CardUtil.cards[cardList.get(1)]);
                            fifthTwoLayoutParams.leftMargin = 20;
                            fifth_two.setLayoutParams(fifthTwoLayoutParams);
                            //第五个座位
                            if ("3".equals(cardCount)) {
                                //第五个座位
                                fifthOneLayoutParams.rightMargin = 40;
                                fifth_one.setLayoutParams(fifthOneLayoutParams);

                                fifthTwoLayoutParams.rightMargin = 20;
                                fifth_two.setLayoutParams(fifthTwoLayoutParams);

                                fifth_three.setImageResource(CardUtil.cards[cardList.get(2)]);
                                fifthThreeLayoutParams.leftMargin = 40;
                                fifth_three.setLayoutParams(fifthThreeLayoutParams);
                            } else if ("4".equals(cardCount)) {
                                //第五个座位
                                fifthOneLayoutParams.rightMargin = 40;
                                fifth_one.setLayoutParams(fifthOneLayoutParams);

                                fifthTwoLayoutParams.rightMargin = 20;
                                fifth_two.setLayoutParams(fifthTwoLayoutParams);

                                fifth_three.setImageResource(CardUtil.cards[cardList.get(2)]);
                                fifthThreeLayoutParams.leftMargin = 40;
                                fifth_three.setLayoutParams(fifthThreeLayoutParams);
                                //第五个座位
                                fifthOneLayoutParams.rightMargin = 60;
                                fifth_one.setLayoutParams(fifthOneLayoutParams);

                                fifthTwoLayoutParams.rightMargin = 40;
                                fifth_two.setLayoutParams(fifthTwoLayoutParams);

                                fifthThreeLayoutParams.leftMargin = 20;
                                fifth_three.setLayoutParams(fifthThreeLayoutParams);

                                fifth_four.setImageResource(CardUtil.cards[cardList.get(3)]);
                                fifthFourLayoutParams.leftMargin = 60;
                                fifth_four.setLayoutParams(fifthFourLayoutParams);
                            } else if ("5".equals(cardCount)) {
                                //第五个座位
                                fifthOneLayoutParams.rightMargin = 40;
                                fifth_one.setLayoutParams(fifthOneLayoutParams);

                                fifthTwoLayoutParams.rightMargin = 20;
                                fifth_two.setLayoutParams(fifthTwoLayoutParams);

                                fifth_three.setImageResource(CardUtil.cards[cardList.get(2)]);
                                fifthThreeLayoutParams.leftMargin = 40;
                                fifth_three.setLayoutParams(fifthThreeLayoutParams);
                                //第五个座位
                                fifthOneLayoutParams.rightMargin = 60;
                                fifth_one.setLayoutParams(fifthOneLayoutParams);

                                fifthTwoLayoutParams.rightMargin = 40;
                                fifth_two.setLayoutParams(fifthTwoLayoutParams);

                                fifthThreeLayoutParams.leftMargin = 20;
                                fifth_three.setLayoutParams(fifthThreeLayoutParams);

                                fifth_four.setImageResource(CardUtil.cards[cardList.get(3)]);
                                fifthFourLayoutParams.leftMargin = 60;
                                fifth_four.setLayoutParams(fifthFourLayoutParams);
                                //第五个座位
                                fifthOneLayoutParams.rightMargin = 80;
                                fifth_one.setLayoutParams(fifthOneLayoutParams);

                                fifthTwoLayoutParams.rightMargin = 60;
                                fifth_two.setLayoutParams(fifthTwoLayoutParams);

                                fifthThreeLayoutParams.rightMargin = 20;
                                fifth_three.setLayoutParams(fifthThreeLayoutParams);

                                fifthFourLayoutParams.leftMargin = 40;
                                fifth_four.setLayoutParams(fifthFourLayoutParams);

                                fifth_five.setImageResource(CardUtil.cards[cardList.get(4)]);
                                fifthFiveLayoutParams.leftMargin = 80;
                                fifth_five.setLayoutParams(fifthFiveLayoutParams);
                            }
                        }
                    }
                } else if ("007".equals(respType)) {
                    String cardIndex = intent.getStringExtra("cardIndex");
                    String seatNo = intent.getStringExtra("seatNo");
                    int relativeSeatNo = getRelativeSeatNo(Integer.parseInt(seatNo));
                    if (1 == relativeSeatNo) {
                        //第二个座位
                        if ("3".equals(cardIndex)) {
                            //第二个座位
                            secondOneLayoutParams.rightMargin = 40;
                            second_one.setLayoutParams(secondOneLayoutParams);

                            secondTwoLayoutParams.rightMargin = 20;
                            second_two.setLayoutParams(secondTwoLayoutParams);

                            second_three.setImageResource(CardUtil.cards[54]);
                            secondThreeLayoutParams.leftMargin = 40;
                            second_three.setLayoutParams(secondThreeLayoutParams);
                        } else if ("4".equals(cardIndex)) {
                            //第二个座位
                            secondOneLayoutParams.rightMargin = 60;
                            second_one.setLayoutParams(secondOneLayoutParams);

                            secondTwoLayoutParams.rightMargin = 40;
                            second_two.setLayoutParams(secondTwoLayoutParams);

                            secondThreeLayoutParams.leftMargin = 20;
                            second_three.setLayoutParams(secondThreeLayoutParams);

                            second_four.setImageResource(CardUtil.cards[54]);
                            secondFourLayoutParams.leftMargin = 60;
                            second_four.setLayoutParams(secondFourLayoutParams);
                        } else if ("5".equals(cardIndex)) {
                            //第二个座位
                            secondOneLayoutParams.rightMargin = 80;
                            second_one.setLayoutParams(secondOneLayoutParams);

                            secondTwoLayoutParams.rightMargin = 60;
                            second_two.setLayoutParams(secondTwoLayoutParams);

                            secondThreeLayoutParams.rightMargin = 20;
                            second_three.setLayoutParams(secondThreeLayoutParams);

                            secondFourLayoutParams.leftMargin = 40;
                            second_four.setLayoutParams(secondFourLayoutParams);

                            second_five.setImageResource(CardUtil.cards[54]);
                            secondFiveLayoutParams.leftMargin = 80;
                            second_five.setLayoutParams(secondFiveLayoutParams);
                        }
                    } else if (2 == relativeSeatNo) {
                        //第三个座位
                        if ("3".equals(cardIndex)) {
                            //第三个座位
                            thirdOneLayoutParams.rightMargin = 40;
                            third_one.setLayoutParams(thirdOneLayoutParams);

                            thirdTwoLayoutParams.rightMargin = 20;
                            third_two.setLayoutParams(thirdTwoLayoutParams);

                            third_three.setImageResource(CardUtil.cards[54]);
                            thirdThreeLayoutParams.leftMargin = 40;
                            third_three.setLayoutParams(thirdThreeLayoutParams);

                        } else if ("4".equals(cardIndex)) {
                            //第三个座位
                            thirdOneLayoutParams.rightMargin = 60;
                            third_one.setLayoutParams(thirdOneLayoutParams);

                            thirdTwoLayoutParams.rightMargin = 40;
                            third_two.setLayoutParams(thirdTwoLayoutParams);

                            thirdThreeLayoutParams.leftMargin = 20;
                            third_three.setLayoutParams(thirdThreeLayoutParams);

                            third_four.setImageResource(CardUtil.cards[54]);
                            thirdFourLayoutParams.leftMargin = 60;
                            third_four.setLayoutParams(thirdFourLayoutParams);
                        } else if ("5".equals(cardIndex)) {
                            //第三个座位
                            thirdOneLayoutParams.rightMargin = 80;
                            third_one.setLayoutParams(thirdOneLayoutParams);

                            thirdTwoLayoutParams.rightMargin = 60;
                            third_two.setLayoutParams(thirdTwoLayoutParams);

                            thirdThreeLayoutParams.rightMargin = 20;
                            third_three.setLayoutParams(thirdThreeLayoutParams);

                            thirdFourLayoutParams.leftMargin = 40;
                            third_four.setLayoutParams(thirdFourLayoutParams);

                            third_five.setImageResource(CardUtil.cards[54]);
                            thirdFiveLayoutParams.leftMargin = 80;
                            third_five.setLayoutParams(thirdFiveLayoutParams);
                        }
                    } else if (3 == relativeSeatNo) {
                        //第四个座位
                        if ("3".equals(cardIndex)) {
                            //第四个座位
                            fourthOneLayoutParams.rightMargin = 40;
                            fourth_one.setLayoutParams(fourthOneLayoutParams);

                            fourthTwoLayoutParams.rightMargin = 20;
                            fourth_two.setLayoutParams(fourthTwoLayoutParams);

                            fourth_three.setImageResource(CardUtil.cards[54]);
                            fourthThreeLayoutParams.leftMargin = 40;
                            fourth_three.setLayoutParams(fourthThreeLayoutParams);
                        } else if ("4".equals(cardIndex)) {
                            //第四个座位
                            fourthOneLayoutParams.rightMargin = 60;
                            fourth_one.setLayoutParams(fourthOneLayoutParams);

                            fourthTwoLayoutParams.rightMargin = 40;
                            fourth_two.setLayoutParams(fourthTwoLayoutParams);

                            fourthThreeLayoutParams.leftMargin = 20;
                            fourth_three.setLayoutParams(fourthThreeLayoutParams);

                            fourth_four.setImageResource(CardUtil.cards[54]);
                            fourthFourLayoutParams.leftMargin = 60;
                            fourth_four.setLayoutParams(fourthFourLayoutParams);

                        } else if ("5".equals(cardIndex)) {
                            //第四个座位
                            fourthOneLayoutParams.rightMargin = 80;
                            fourth_one.setLayoutParams(fourthOneLayoutParams);

                            fourthTwoLayoutParams.rightMargin = 60;
                            fourth_two.setLayoutParams(fourthTwoLayoutParams);

                            fourthThreeLayoutParams.rightMargin = 20;
                            fourth_three.setLayoutParams(fourthThreeLayoutParams);

                            fourthFourLayoutParams.leftMargin = 40;
                            fourth_four.setLayoutParams(fourthFourLayoutParams);

                            fourth_five.setImageResource(CardUtil.cards[54]);
                            fourthFiveLayoutParams.leftMargin = 80;
                            fourth_five.setLayoutParams(fourthFiveLayoutParams);
                        }
                    } else if (4 == relativeSeatNo) {
                        //第五个座位
                        if ("3".equals(cardIndex)) {
                            //第五个座位
                            fifthOneLayoutParams.rightMargin = 40;
                            fifth_one.setLayoutParams(fifthOneLayoutParams);

                            fifthTwoLayoutParams.rightMargin = 20;
                            fifth_two.setLayoutParams(fifthTwoLayoutParams);

                            fifth_three.setImageResource(CardUtil.cards[54]);
                            fifthThreeLayoutParams.leftMargin = 40;
                            fifth_three.setLayoutParams(fifthThreeLayoutParams);
                        } else if ("4".equals(cardIndex)) {
                            //第五个座位
                            fifthOneLayoutParams.rightMargin = 60;
                            fifth_one.setLayoutParams(fifthOneLayoutParams);

                            fifthTwoLayoutParams.rightMargin = 40;
                            fifth_two.setLayoutParams(fifthTwoLayoutParams);

                            fifthThreeLayoutParams.leftMargin = 20;
                            fifth_three.setLayoutParams(fifthThreeLayoutParams);

                            fifth_four.setImageResource(CardUtil.cards[54]);
                            fifthFourLayoutParams.leftMargin = 60;
                            fifth_four.setLayoutParams(fifthFourLayoutParams);
                        } else if ("5".equals(cardIndex)) {
                            //第五个座位
                            fifthOneLayoutParams.rightMargin = 80;
                            fifth_one.setLayoutParams(fifthOneLayoutParams);

                            fifthTwoLayoutParams.rightMargin = 60;
                            fifth_two.setLayoutParams(fifthTwoLayoutParams);

                            fifthThreeLayoutParams.rightMargin = 20;
                            fifth_three.setLayoutParams(fifthThreeLayoutParams);

                            fifthFourLayoutParams.leftMargin = 40;
                            fifth_four.setLayoutParams(fifthFourLayoutParams);

                            fifth_five.setImageResource(CardUtil.cards[54]);
                            fifthFiveLayoutParams.leftMargin = 80;
                            fifth_five.setLayoutParams(fifthFiveLayoutParams);
                        }
                    }
                } else if ("008".equals(respType)) {
                    String cardIndex = intent.getStringExtra("cardIndex");
                    int card = Integer.parseInt(intent.getStringExtra("card"));

                    if ("3".equals(cardIndex)) {
                        //第一个座位
                        firstOneLayoutParams.rightMargin = 40;
                        first_one.setLayoutParams(firstOneLayoutParams);

                        firstTwoLayoutParams.rightMargin = 20;
                        first_two.setLayoutParams(firstTwoLayoutParams);

                        first_three.setImageResource(CardUtil.cards[card]);
                        selfCards.add(card);
                        firstThreeLayoutParams.leftMargin = 40;
                        first_three.setLayoutParams(firstThreeLayoutParams);
                    } else if ("4".equals(cardIndex)) {
                        //第一个座位
                        firstOneLayoutParams.rightMargin = 60;
                        first_one.setLayoutParams(firstOneLayoutParams);

                        firstTwoLayoutParams.rightMargin = 40;
                        first_two.setLayoutParams(firstTwoLayoutParams);

                        firstThreeLayoutParams.leftMargin = 20;
                        first_three.setLayoutParams(firstThreeLayoutParams);

                        first_four.setImageResource(CardUtil.cards[card]);
                        selfCards.add(card);
                        firstFourLayoutParams.leftMargin = 60;
                        first_four.setLayoutParams(firstFourLayoutParams);
                    } else if ("5".equals(cardIndex)) {
                        //第一个座位
                        firstOneLayoutParams.rightMargin = 80;
                        first_one.setLayoutParams(firstOneLayoutParams);

                        firstTwoLayoutParams.rightMargin = 60;
                        first_two.setLayoutParams(firstTwoLayoutParams);

                        firstThreeLayoutParams.rightMargin = 20;
                        first_three.setLayoutParams(firstThreeLayoutParams);

                        firstFourLayoutParams.leftMargin = 40;
                        first_four.setLayoutParams(firstFourLayoutParams);

                        first_five.setImageResource(CardUtil.cards[card]);
                        selfCards.add(card);
                        firstFiveLayoutParams.leftMargin = 80;
                        first_five.setLayoutParams(firstFiveLayoutParams);
                    }

                    //需要指针指向自己时，符合条件才可以点击下一家或者房主进行开牌，这时候手中牌有三张及以上
                    //手中有一张牌A且A的值转换成11时大于16点且小于21点
                    if (((CardUtil.getACardCount(selfCards) > 0 && CardUtil.getSecondSizeCardValue(selfCards) >= 16 && CardUtil.getSecondSizeCardValue(selfCards) <= 21)
                            //手中有一张牌A，值是1时，大小大于16点
                            || (CardUtil.getACardCount(selfCards) > 0 && CardUtil.getFirstSizeCardValue(selfCards) >= 16)
                            //手中牌没有A，但是大小大于16点
                            || (CardUtil.getACardCount(selfCards) == 0 && CardUtil.getFirstSizeCardValue(selfCards) >= 16)) && pointerSeatNo.equals(selfSeatNo)) {
                        iv_next_player.setImageResource(R.drawable.select_next);
                        tv_next_player.setText("下一家");
                        iv_next_player.setClickable(true);
                        if ("0".equals(selfSeatNo)) {
                            iv_next_player.setImageResource(R.drawable.select_eye);
                            tv_next_player.setText("全部开牌");
                            iv_next_player.setClickable(true);

                            if ("2".equals(userLimit)) {
                                if (secondEye) {
                                    second_eye.setImageResource(R.drawable.select_eye);
                                    second_eye.setClickable(true);
                                }

                            } else if ("3".equals(userLimit)) {
                                if (secondEye) {
                                    second_eye.setImageResource(R.drawable.select_eye);
                                    second_eye.setClickable(true);
                                }
                                if (thirdEye) {
                                    third_eye.setImageResource(R.drawable.select_eye);
                                    third_eye.setClickable(true);
                                }

                            } else if ("4".equals(userLimit)) {
                                if (secondEye) {
                                    second_eye.setImageResource(R.drawable.select_eye);
                                    second_eye.setClickable(true);
                                }
                                if (thirdEye) {
                                    third_eye.setImageResource(R.drawable.select_eye);
                                    third_eye.setClickable(true);
                                }
                                if (fourthEye) {
                                    fourth_eye.setImageResource(R.drawable.select_eye);
                                    fourth_eye.setClickable(true);
                                }

                            } else if ("5".equals(userLimit)) {
                                if (secondEye) {
                                    second_eye.setImageResource(R.drawable.select_eye);
                                    second_eye.setClickable(true);
                                }
                                if (thirdEye) {
                                    third_eye.setImageResource(R.drawable.select_eye);
                                    third_eye.setClickable(true);
                                }
                                if (fourthEye) {
                                    fourth_eye.setImageResource(R.drawable.select_eye);
                                    fourth_eye.setClickable(true);
                                }
                                if (fifthEye) {
                                    fifth_eye.setImageResource(R.drawable.select_eye);
                                    fifth_eye.setClickable(true);
                                }

                            }
                        }
                    } else {
                        tv_next_player.setText("");
                        iv_next_player.setImageResource(CardUtil.cards[55]);
                        iv_next_player.setClickable(false);
                    }

                } else if ("012".equals(respType)) {
                    String userChip = intent.getStringExtra("userChip");
                    selfChip += Integer.parseInt(userChip);
                    tv_self_chip.setText((selfChip - defaultEscrowValue) + "");
                } else if ("013".equals(respType)) {
                    String bankerChip = intent.getStringExtra("bankerChip");

                    player_settlement = (LinearLayout) UserRoomActivity.this.getLayoutInflater().inflate(R.layout.player_settlement, null);

                    banker_chip = player_settlement.findViewById(R.id.banker_chip);
                    self_chip = player_settlement.findViewById(R.id.self_chip);
                    return_main = player_settlement.findViewById(R.id.return_main);
                    return_main.setOnClickListener(UserRoomActivity.this);
                    banker_chip.setText(bankerChip);
                    self_chip.setText(selfChip + "");
                    settlementDialog = new AlertDialog.Builder(UserRoomActivity.this)
                            .setView(player_settlement)
                            .create();
                    settlementDialog.setCancelable(false);
                    settlementDialog.show();

                    Intent bankerSettlementIntent = new Intent(CustomAction.SERVICE_ACTION);
                    Map<String, Object> bsMap = new HashMap<>();
                    bsMap.put("reqType", "bankerSettlementReq");
                    bsMap.put("seatId", selfSeatId);
                    bsMap.put("chip", selfChip);
                    bankerSettlementIntent.putExtra("request", JSONObject.toJSON(bsMap).toString());
                    sendBroadcast(bankerSettlementIntent);
                } else if ("014".equals(respType)) {
                    String playerChip = intent.getStringExtra("playerChip");
                    String playerSeatNo = intent.getStringExtra("seatNo");
                    //判断结算筹码的玩家筹码顺序
                    if ("1".equals(playerSeatNo)) {
                        secondMap.put("playerChip", playerChip);
                        playerList.add(secondMap);
                    } else if ("2".equals(playerSeatNo)) {
                        thirdMap.put("playerChip", playerChip);
                        playerList.add(thirdMap);
                    } else if ("3".equals(playerSeatNo)) {
                        fourthMap.put("playerChip", playerChip);
                        playerList.add(fourthMap);
                    } else if ("4".equals(playerSeatNo)) {
                        fifthMap.put("playerChip", playerChip);
                        playerList.add(fifthMap);
                    }

                    if (userLimit.equals(playerList.size() + 1 + "")) {
                        PlayerListAdapter PlayerListAdapter = new PlayerListAdapter(UserRoomActivity.this, playerList);
                        player_list = banker_settlement.findViewById(R.id.lv_player_list);
                        player_list.setAdapter(PlayerListAdapter);
                        bankerDialog.show();
                    }
                }
            } catch (Exception e) {
                Toast.makeText(UserRoomActivity.this, "数据丢失，请检查网络", Toast.LENGTH_SHORT).show();
            }
        }
    }
}
